<?php

if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Dayrui Website Management System
 *
 * @since		version 2.0.0
 * @author		Dayrui <dayrui@gmail.com>
 * @license     http://www.dayrui.com/license
 * @copyright   Copyright (c) 2011 - 9999, Dayrui.Com, Inc.
 * @filesource	svn://www.dayrui.net/v2/news/core/M_Controller.php
 */
	
require FCPATH.'dayrui/core/D_Module.php';

class M_Controller extends D_Module {

    /**
     * 构造函数继承公共Module类
     */
    public function __construct() {
        parent::__construct();
    }


    public function check($id, $type = 'extend') {
	    $this->code = 0;
	    $id = $id ? $id : (int)$this->input->get('id');
	    $type = $type ? $type : $this->input->get('type');
	    if($this->member['uid'] < 1) {
		    $this->msg = '没有登陆';
		    return false;
	    }
	    if($type == 'extend') {
		    $content = $this->_extend($id, TRUE);		    
	    } else {
		    $content = $this->_show($id, 1, TRUE);
	    }	    
	    if(!$content) {
		    $this->msg = '视频不存在';
		    return false;
	    }
	    $video_id = ($type == 'extend') ? $content[0]['cid'] : $content[0]['id'];    
	    $r = $this->link->where("`video_id` = '".$video_id."' AND `mid` = '".$this->member['uid']."'")->limit(1)->get('member_video_selection')->row_array();	    
	    if($r) {
		    $this->msg = '请勿重新选课';
		    $r['extra_ids'] = json_decode($r['extra_ids'], true);
		    return $r;
	    } else {
		    $this->code = 1;
		    return false;
	    }
    }
}